<template>
  <div class="box">
    <div class="boxheader">
      <span class="meeting-title"><img src="~@/assets/img/left-border.png"
             alt=""> 我的缴费统计</span>
      <div class="select">
        <el-date-picker v-model="value2"
                        style="width: 100%"
                        format="yyyy-MM"
                        value-format="yyyy-MM"
                        type="month"
                        @change="onchange"
                        placeholder="选择月">
        </el-date-picker>
      </div>
    </div>
    <div class="chart-box">
      <echarts :data="chartData"
               ref="chart"
               class="echart"
               refName='chart'
               :heightNum="390" />
      <svg width="100%"
           height="100%">
        <defs>
          <linearGradient id="colors"
                          x1="0%"
                          y1="0%"
                          x2="100%"
                          y2="0%">
            <stop offset="0%"
                  style="stop-color:#0579c5"
                  stop-opacity="1"></stop>
            <stop offset="100%"
                  style="stop-color:#13ccef"
                  stop-opacity="1"></stop>
          </linearGradient>
        </defs>
      </svg>
    </div>
  </div>
</template>

<script>
import echarts from '@/components/echarts'
import { dateFormat } from '@/utils'
export default {
  data () {
    return {
      value2: dateFormat('YYYY-mm', new Date()),
      chartData: {
        data: {
          columns: ['入住', '退宿'],
          rows: [
            { '入住': '入住', '退宿': 12 },
            { '入住': '退宿', '退宿': 50 }
          ]
        },
        colors: [ '#F29423', '#2AB07A', '#BEBEBE' ],
        chartSettings: {
          type: 'ring'
          // radius: '35%'
        },
        extend: {
          legend: {
            bottom: 10,
            itemGap: 20,
            textStyle: {
              color: '#666'
            }
          },
          label: {
            color: '#666',
            formatter: '{d}%\n{c}'
          },
          grid: {
            top: '10'
            // bottom: '0'
          },
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          // }
          }
        }
      }
    }
  },
  components: {
    echarts
  },
  mounted () {
    this.onchange()
  },
  methods: {
    formatStatus (val) {
      if (val === 0) {
        return '未缴费'
      }
      if (val === 1) {
        return '已缴费'
      }
      if (val === 2) {
        return '已免缴'
      }
    },
    onchange () {
      let str = ''
      if (this.value2) {
        let startDate = dateFormat('YYYY-mm-dd HH:MM:SS', new Date(this.value2.split('-')[0], this.value2.split('-')[1] - 1, 1))
        let endDate = dateFormat('YYYY-mm-dd', new Date(this.value2.split('-')[0], this.value2.split('-')[1], 0))
        str = '?startDate=' + startDate + '&endDate=' + endDate + ' 23:59:59'
        this.$http.get('/tb/workbench/getMyPayStatistics' + str).then(({ data: res }) => {
          if (res.code !== 0) {
            return
          }
          let temp = []
          let arr = []
          for (let i = 0; i < 3; i++) {
            let arr1 = {}
            if (res.data[i]) {
              arr1.label = this.formatStatus(res.data[i].status)
              arr1.quantity = res.data[i].quantity
            } else {
              arr1.label = this.formatStatus(i)
              arr1.quantity = 0
            }
            temp.push(arr1)
          }
          temp.map((ress) => {
            arr.push({ '入住': ress.label, '退宿': ress.quantity })
          })
          this.chartData.data.rows = arr
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.box {
  width: 100%;
  height: 340px;
  padding: 10px 0 0 10px;
  position: relative;
  .boxheader {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .meeting-title {
    color: #333;
    line-height: 40px;
    font-size: 18px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
  .chart-box {
    position: relative;
    margin-top: 10px;
    .echart {
      margin-top: -70px;
    }
  }
}
.select {
  color: #333;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30%;
  height: 30px;
  z-index: 1000;
}
::deep .el-select-dropdown {
  min-width: 142px !important;
}
::deep .v-charts-data-empty {
  top: 10px !important;
}
</style>
